<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>5_2_2-1-$emit方法传递事件</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">
    <my-alert @myclick="appfunc" title="按钮1"></my-alert>
    <my-alert title="按钮2"></my-alert>
  </div>

  <script>
    const App = Vue.createApp({
      methods: {
        appfunc() {
          console.log("点击了自定义组件-");
        },
      },
    }); //创建一个VUE应用
    const alertComponent = {
      //创建一个名为alertComponent的组件
      props: ["title"],
      template: `<div><button @click="myclick">{{title}}</button></div>`,
    };
    App.component("my-alert", alertComponent); //component定义组件，组件名/配置
    App.mount("#Application"); //mount方法绑定到指定实例
  </script>
</body>

</html>